package 代码记录.指定公司代码练习记录.华为_2024.分值100;

import java.util.Scanner;

/**
 * @author zx
 * @create 2024-02-02 20:06
 * 二分，自己做不出来，二刷
 */
public class 机器人搬砖_23 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] temp = sc.nextLine().split(" ");
        int[] arr = new int[temp.length];
        for (int i = 0; i < temp.length; i++) {
            arr[i] = Integer.parseInt(temp[i]);
        }
        System.out.println(minE(arr, 8));
    }

    public static int minE(int[] arr, int H) {
        int max = Integer.MIN_VALUE;
        for(int i = 0;i < arr.length;i++){
            max = Math.max(arr[i], max);
        }
        return binarySearch(arr, 1, max, H);
    }

    private static boolean canPaint(int[] arr, int m, int H) {
        int sum = 0;
        for(int i = 0;i < arr.length;i++){
            sum += (arr[i] + m - 1) / m;
        }
        return sum <= H;
    }

    private static int binarySearch(int[] arr, int left, int right, int H) {
        if (left > right) {
            return -1;
        }

        int mid = left + ((right - left) >> 1);
        if (canPaint(arr, mid, H)) {
            int result = binarySearch(arr, left, mid - 1, H);
            return result == -1 ? mid : result;
        } else {
            return binarySearch(arr, mid + 1, right, H);
        }
    }
}
